﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace EDTS.Weixin.Submits
{
    /// <summary>
    /// 微信公众号，成员相关操作
    /// </summary>
    public class User
    {
        /// <summary>
        /// 创建成员
        /// </summary>
        /// <param name="token"></param>
        /// <param name="username"></param>
        /// <param name="realname"></param>
        /// <param name="dep"></param>
        /// <param name="mobile"></param>
        /// <param name="email"></param>
        /// <param name="weixinid"></param>
        public static void Create(string token, string username,string realname,int dep,string mobile,string email,string weixinid)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/create";
            var obj = new { userid = username, name = realname, department = new int[] { dep }, mobile = mobile, email = email, weixinid = weixinid };
            Submit.Post(token, url, obj);
        }
        /// <summary>
        /// 修改成员
        /// </summary>
        /// <param name="token"></param>
        /// <param name="username"></param>
        /// <param name="realname"></param>
        /// <param name="dep"></param>
        /// <param name="mobile"></param>
        /// <param name="email"></param>
        /// <param name="weixinid"></param>
        public static void Update(string token, string username, string realname, int dep, string mobile, string email, string weixinid)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/update";
            var obj = new { userid = username, name = realname, department = new int[] { dep }, mobile = mobile, email = email, weixinid = weixinid };
            Submit.Post(token, url, obj);
        }
        /// <summary>
        /// 删除成员
        /// </summary>
        /// <param name="token"></param>
        /// <param name="username"></param>
        public static void Delete(string token, string username)
        {
            var url = "https://qyapi.weixin.qq.com/cgi-bin/user/delete";
            var parameters = new List<KeyValuePair<string, string>>();
            parameters.Add(new KeyValuePair<string, string>("userid", username));
            Submit.Get(token, url, parameters);
        }
    }
}
